<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="flex-1" :model="formState" :colon="false" :label-col="{ style: { width: '70px' } }">
        <a-form-item name="zjm" class="w-1/4">
          <a-input v-model:value="formState.zjm" placeholder="诊断代码/诊断名称/助记码" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <div class="mb-3">
        <BaseExport type="运维" name="中医诊断" code="00001164" :search-params="formState">导出</BaseExport>
        <!-- <a-button @click="onExport">导出</a-button> -->
      </div>
      <BaseTable :loading="loading" column-code="00001164" :data-source="tableData" :pagination="pagination" :scroll="{ x: 1000 }" fill>
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'statusStr'">
            <a-switch v-model:checked="record.status" checked-value="0" un-checked-value="1" @change="onClickStatus(record, $event)" />
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'

const formState = ref({})
const formRef = ref(null)
const { loading, tableData, pagination, getData } = useTable({
  url: '/operation/opex/getDictICD10TcmInfoList',
  immediate: true,
  params: formState.value,
  formatResult: (record) => {
    record.status = record.status ? '1' : '0'
    return record
  }
})

const onClickStatus = async (record, state) => {
  if (state === '1') {
    const res = await post('/operation/opex/doEnableDictICD10Tcm', record)
    if (res.code !== 0) return message.error(res.msg)
    message.success(res.msg)
  } else {
    const res = await post('/operation/opex/doDisableDictICD10Tcm', record)
    if (res.code !== 0) return message.error(res.msg)
    message.success(res.msg)
  }
  getData()
}
</script>

<style lang="less" scoped></style>
